<template>
	<view>
		<view class="m-tab">
			<view class="m-tab-item" @click="clickTabFun(item,index)" :class="{'m-tab-active':params.scene == item.id}"
				v-for="(item,index) in listTab" :key="index">
				<text>{{item.name}}</text>
			</view>
		</view>

		<view class="m-list">
			<view class="m-item" v-for="(item,index) in list" :key="index" @click="to_link('/pages2/shop-order-detail/shop-order-detail?id='+item.id)">
				<view class="m-item-top">
					<view class="m-item-top__left">
						<text>订单号：{{item.order_id}}</text>
					</view>
					<view class="m-item-top__right">
						<text>{{item.status_info}}</text>
					</view>
				</view>
				<view class="goods" v-for="(val,key) in item.products" :key="key">
					<view class="goods-image">
						<image :src="val.image" mode="aspectFill"></image>
					</view>
					<view class="goods-content">
						<view class="goods-name u-line-1">
							<text>{{val.title}}</text>
						</view>
						<view class="goods-spec">
							<text>{{val.key_vals}}</text>
						</view>
						<view class="goods-bottom">
							<view class="goods-num">
								<text>x{{val.num}}</text>
							</view>
							<view class="">
								<text class="goods-price">{{val.price_sale}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="m-item-bottom">
					<view class="m-item-bottom__left">
						<view class="">
							<text>下单时间：{{item.dtTime}}</text>
						</view>
						<view class="">
							<text>订单金额：{{item.price}}积分</text>
						</view>
					</view>
					<view class="m-item-bottom__right">
						<view class="m-item-btn m-item-btn__cancel">
							<text>订单详情</text>
						</view>

						<view class="m-item-btn m-item-btn__extend"  v-if="item.status == -5">
							<text>立即支付</text>
						</view>
						<!-- <view class="m-item-btn m-item-btn__extend">
							<text>再次预定</text>
						</view> -->
					</view>
				</view>
			</view>

			<view class="m-empty" v-if="loading == 'noMore' && list.length == 0">
				<image src="../static/hotel/hotel-order-empty.png" mode=""></image>
				<view class="m-empty-text">
					<text>暂无订单</text>
				</view>
			</view>
			<uni-load-more :status="loading" v-else></uni-load-more>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listTab: [{
					id: 0,
					name: '全部'
				}, {
					id: 2,
					name: '待发货'
				}, {
					id: 3,
					name: '待收货'
				}, {
					id: 4,
					name: '已完成'
				}],
				
				loading:'loading',
				list:[],
				params:{
					page:1,
					pagenum:10,
					scene:0
				},
			}
		},
		onLoad(opt) {
			this.params.scene = opt.type || 0
			this.getListFun()
		},
		methods: {
			clickTabFun(item, index) {
				if(this.params.scene == item.id) return false;
				this.params.scene = item.id
				this.params.page = 1
				this.list = []
				this.getListFun()
			},
			getListFun(){
				this.loading = 'loading'
				let params = this.params
				this.$http.getJson('orders_lists',params).then(res=>{
					if(res.code == 1){
						let list = res.data || []
						let len = list.length 
						if(len > 0){
							this.list = this.list.concat(list)
						}
						if(len == params.pagenum){
							this.loading = 'more'
							params.page += 1
						}else{
							this.loading = 'noMore'
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background: #f6f6f6;
	}

	.m-tab {
		position: fixed;
		display: flex;
		width: 750rpx;
		height: 100rpx;
		background-color: #fff;

		.m-tab-item {
			display: flex;
			justify-content: center;
			align-items: center;
			flex: 1;
			height: 100%;
			font-size: 28rpx;
			color: #75706A;
		}

		.m-tab-active {
			position: relative;
			font-size: 32rpx;
			color: #34302D;
			font-weight: 600;

			&::after {
				content: '';
				display: block;
				position: absolute;
				bottom: 0;
				left: 50%;
				transform: translateX(-50%);
				width: 56rpx;
				height: 6rpx;
				background: #D3A358;
			}
		}
	}

	.m-list {
		padding-top: 120rpx;

		.m-item {
			background: #fff;
			padding: 0 25rpx;
			margin-bottom: 20rpx;

			.m-item-top {
				display: flex;
				justify-content: space-between;
				padding: 30rpx 0; 

				.m-item-top__left {
					font-size: 24rpx;
					color: #34302D;
				}

				.m-item-top__right {
					font-size: 24rpx;
					color: #D3A358;
				}
			}

			.m-item-bottom {
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 24rpx;
				padding-top: 23rpx;
				padding-bottom: 23rpx;
				border-top: 1px solid #E6E3DE;

				.m-item-bottom__left {
					font-size: 24rpx;
					color: #75706A;
					line-height: 36rpx;
				}

				.m-item-bottom__right {
					display: flex;
					align-items: center;

					.m-item-btn {
						display: flex;
						align-items: center;
						justify-content: center;
						width: 136rpx;
						height: 48rpx;
						background: #FFFFFF;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						border: 2rpx solid #D3A358;
						font-size: 24rpx;
						color: #D3A358;
						margin-left: 20rpx;
					}

					.m-item-btn__extend {
						background: #D3A358;
						color: #fff;
					}

					.m-item-btn__cancel {
						border-color: #E6E3DE;
						color: #75706A;
					}
				}
			}
		}
	}
	
	.goods{
		display: flex;
		padding: 20rpx 0;
		border-top: 1px solid #E6E3DE;
		.goods-image{
			width: 140rpx;
			height: 140rpx;
			image{
				width: 100%;
				height: 100%;
			}
		}
		.goods-content{
			width: 540rpx;
			margin-left: 20rpx;
			.goods-name{
				font-size: 28rpx;
				color: #34302D;
				line-height: 40rpx;
				font-weight: 800;
				margin-top: 4rpx;
			}
			.goods-spec{
				font-size: 24rpx;
				color: #9A958F;
				margin-top: 8rpx;
				height: 33rpx;
				line-height: 33rpx;
			}
			.goods-bottom{
				display: flex;
				justify-content: space-between;
				align-items: center;
				.goods-num{
					font-size: 24rpx;
					color: #9A958F;
				}
				.goods-price{
					font-size: 40rpx;
					color: #DE2C38;
					&::after{
						content: '积分';
						font-size: 24rpx;
						color: #76706B;
						margin-left: 5rpx;
					}
				}
			}
		}
	}

	.m-empty {
		display: flex;
		flex-direction: column;
		text-align: center;
		align-items: center;
		font-size: 26rpx;
		color: #ADAAA5;
		padding-top: 150rpx;

		image {
			width: 320rpx;
			height: 260rpx;
			margin-bottom: 30rpx;
		}
	}
</style>